package cjq.demo.thread.ch5_4;

import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/5/3.
 */
public class Main {
    public static void main(String[] args) {
        ForkJoinPool pool = new ForkJoinPool();
        FolderProcessor system = new FolderProcessor("D:\\workspace\\hello-world\\src","java");
        FolderProcessor apps = new FolderProcessor("D:\\workspace\\jfinal\\src\\com","java");
        FolderProcessor documents = new FolderProcessor("C:\\Program Files","log");

        pool.execute(system);
        pool.execute(apps);
        pool.execute(documents);

        do{
            System.out.println("*************************");
            System.out.println("Main: Parallelism :"+pool.getParallelism());
            System.out.println("Main: Active Threads  :"+pool.getActiveThreadCount());
            System.out.println("Main: getQueuedTaskCount :"+pool.getQueuedTaskCount());
            System.out.println("Main: getStealCount :"+pool.getStealCount());
            System.out.println("**************************");
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }while((!system.isDone())||(!apps.isDone())||(!documents.isDone()));

        pool.shutdown();

        List<String> results = system.join();
        System.out.println("System: "+results.size()+" files found .");
        results = apps.join();
        System.out.println("apps: "+results.size()+" files found .");
        results = documents.join();
        System.out.println("documents: "+results.size()+" files found .");

    }
}
